//
//  CommendListViewModel.m
//  meiyinxiang
//
//  Created by apple on 2018/1/17.
//  Copyright © 2018年 hbjApple. All rights reserved.
//

#import "CommendListViewModel.h"
#import "CommentModel.h"
#import "CommentViewModel.h"
@implementation CommendListViewModel
- (void)getRecommendListIsPullup:(BOOL)isPullup
                 WithRedPacketId:(NSString *)redPacketId
                    commendManId:(NSString *)commendManId
                          Result:(CompletionBlock)reslut{
    if (isPullup == YES) {
        self.mpage ++;
    }else{//刷新
        self.mpage = 1;
        [self.commentList removeAllObjects];
    }
    NSString *page = [NSString stringWithFormat:@"%ld",self.mpage];
    NSString *size = @"10";
    
    [[MYXHttpManager shared] clickToCommendListWithPage:page size:size RedPacketId:redPacketId recommendManId:commendManId result:^(BOOL success, NSString *msg, NSArray *arrays) {
        if (success) {
            for (NSInteger i = 0; i < arrays.count; i++) {

                CommentModel *commentModel = arrays[i];
                CommentViewModel *commentViewModel = [[CommentViewModel alloc] initWithModel:commentModel];
                if (self.mpage > 1 && i == 0) {
                    [self.commentList replaceObjectAtIndex:0 withObject:commentViewModel];
                }else{
                    [self.commentList addObject:commentViewModel];
                }

            }
            if (arrays.count != 11) {
                reslut(NO);
            }else{
                reslut(YES);
            }
        }else{
            reslut(NO);
        }
    }];
    
}
- (NSMutableArray *)commentList{
    if (_commentList == nil) {
        _commentList = [NSMutableArray array];
    }
    return _commentList;
}
@end
